package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RefineOperBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.Frame.NewRefiningJframe;
import org.come.bean.QualityClBean;
import org.come.entity.Goodstable;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class DianQJpanel extends JPanel {
    public double bili = 1;
    private boolean p = true;
    private boolean zuo = false;
    private boolean you = false;
    public List<String> shuxing = new ArrayList<>();
    public List<Double> shuzhi = new ArrayList<>();
    public QualityClBean clBean;
    public FormsOnOffBtn offBtn;
    public RefineOperBtn operBtn3, operBtn1, operBtn2;
    String[] mes1 = {"加强混乱", "加强封印", "加强昏睡", "加强雷", "加强火", "加强鬼火", "强力克金", "加强克土", "加强克火", "加强克水", "加强克木", "加强风"};

    public DianQJpanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            this.setPreferredSize(new Dimension(470, 315));
            this.setLayout(null);
            this.setOpaque(false);

            // 关闭按钮事件
            offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 127);
            offBtn.setBounds(470 - 35, 10, 25, 25);
            this.add(offBtn);
            operBtn3 = new RefineOperBtn("skin/8100226/button/49.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 2, "再次炼化");
            operBtn3.setBounds(365, 29, 68, 17);
            this.add(operBtn3);
            operBtn1 = new RefineOperBtn("skin/8100226/button/18.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 0,
                    "保 留");
            operBtn1.setBounds(80, 275, 100, 26);
            this.add(operBtn1);
            // 替换新属性
            operBtn2 = new RefineOperBtn("skin/8100226/button/18.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 1,
                    "替 换");
            operBtn2.setBounds(300, 275, 100, 26);
            this.add(operBtn2);
        } else {
            this.setPreferredSize(new Dimension(470, 315));
            this.setLayout(null);
            this.setOpaque(false);

            // 关闭按钮事件
            offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 127);
            offBtn.setBounds(470 - 35, 5, 25, 25);
            this.add(offBtn);
            operBtn3 = new RefineOperBtn("inkImg/hongmu/a7.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 2, "再次炼化");
            operBtn3.setBounds(365, 29, 68, 51);
            this.add(operBtn3);
            operBtn1 = new RefineOperBtn("inkImg/hongmu/a2.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 0,
                    "保 留");
            operBtn1.setBounds(80, 240, 85, 72);
            this.add(operBtn1);
            // 替换新属性
            operBtn2 = new RefineOperBtn("inkImg/hongmu/a2.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 1,
                    "替 换");
            operBtn2.setBounds(300, 240, 85, 72);
            this.add(operBtn2);
        }
    }

    int dianzui1 = 0;
    int diancui2 = 0;
    static ImageIcon icon;
    ImageIcon icon1 = new ImageIcon("inkImg/old/background/S67.png");
    ImageIcon icon2 = new ImageIcon("inkImg/old/2/S154.png");
    int zong = 0;
    int xin = 0;
    static Random rand = new Random();

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/点翠1.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 470, 315, this);
            g.setFont(UIUtils.nameFont);
            g.setColor(Color.white);
            g.drawString("原点翠值属性", 55, 70);
            g.drawString("原点翠值属性", 255, 70);
            if (isP()) {
                g.setColor(Color.black);
                if (isZuo()) {
                    g.drawString("总点翠值", 40, 135);
                    g.drawString(zong == 0 ? "2" : String.valueOf(zong), 170, 135);
                    g.drawImage(icon1.getImage(), 35, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 35, 170, (191), 28, this);

                    g.drawImage(icon2.getImage(), 35, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 35, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_HYK16);
                    g.setColor(Color.yellow);
                    g.drawString(getShuxing().get(0), 45, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(0)), 35 + 140, 140 + 18);
                    g.setColor(Color.yellow);
                    g.drawString(getShuxing().get(1), 45, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(1)), 35 + 140, 175 + 18);
                }
                if (isYou()) {
                    g.setFont(UIUtils.nameFont);
                    g.setColor(Color.black);
                    g.drawString("总点翠值", 40 + 210, 135);
                    g.drawString(xin == 0 ? "2" : String.valueOf(xin), 170 + 210 + 20, 135);
                    g.drawImage(icon1.getImage(), 245, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 245, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 245, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 245, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_HYK16);
                    g.setColor(Color.yellow);
                    g.drawString(getShuxing().get(2), 145 + 100, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(2)), 165 + 220, 140 + 18);
                    g.setColor(Color.yellow);
                    g.drawString(getShuxing().get(3), 145 + 100, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(3)), 165 + 220, 175 + 18);
                }
            }

        } else {
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/点翠红木.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 470, 315, this);
            g.setFont(UIUtils.nameFont);
            g.setColor(Color.orange);
            g.drawString("原点翠值属性", 55, 70);
            g.drawString("原点翠值属性", 255, 70);
            if (isP()) {
                g.setColor(Color.orange);
                if (isZuo()) {
                    g.drawString("总点翠值", 40, 135);
                    g.drawString(zong == 0 ? "2" : String.valueOf(zong), 170, 135);
                    g.drawImage(icon1.getImage(), 35, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 35, 170, (191), 28, this);

                    g.drawImage(icon2.getImage(), 35, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 35, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(0), 45, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(0)), 35 + 140, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(1), 45, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(1)), 35 + 140, 175 + 18);
                }
                if (isYou()) {
                    g.setFont(UIUtils.nameFont);
                    g.setColor(Color.orange);
                    g.drawString("总点翠值", 40 + 210, 135);
                    g.drawString(xin == 0 ? "2" : String.valueOf(xin), 170 + 210 + 20, 135);
                    g.drawImage(icon1.getImage(), 245, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 245, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 245, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 245, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(2), 145 + 100, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(2)), 165 + 220, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(3), 145 + 100, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(3)), 165 + 220, 175 + 18);
                }
            }
        }
    }

    public static double dianchizhi() {

        return 1;
    }

    public double getBili() {
        return dianchizhi();
    }

    public void setBili(double bili) {
        this.bili = bili;
    }

    public List<String> getShuxing() {

        return shuxing;
    }

    public void setShuxing(List<String> shuxing) {
        this.shuxing = shuxing;
    }

    public List<Double> getShuzhi() {

        return shuzhi;
    }

    public void setShuzhi(List<Double> shuzhi) {

        this.shuzhi = shuzhi;
    }

    public void show(String value, int leixing, boolean is) {
        p = true;
        setZuo(false);
        setYou(false);
        shuzhi.clear();
        shuxing.clear();
        shuxing.add("1");
        shuzhi.add(1.0);
        shuxing.add("2");
        shuzhi.add(3.0);
        shuxing.add("1");
        shuzhi.add(1.0);
        shuxing.add("2");
        shuzhi.add(3.0);
        if (value != null) {
            String[] mes1 = value.split("&");
            shuxing.set(0, mes1[1].split("=")[0]);
            shuzhi.set(0, Double.valueOf(mes1[1].split("=")[1]));
            shuxing.set(1, mes1[2].split("=")[0]);
            shuzhi.set(1, Double.valueOf(mes1[2].split("=")[1]));
            zong = Integer.parseInt(mes1[3].split("=")[1]);
            setZuo(true);

        }
        NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().leixing = 0;
        FormsManagement.showForm(127);
    }

    public void ew(QualityClBean clBean) {

        setP(true);

        String[] mes1 = clBean.getNewAttr().split("&");
        shuxing.set(2, mes1[1].split("=")[0]);
        shuzhi.set(2, Double.valueOf(mes1[1].split("=")[1]));
        shuxing.set(3, mes1[2].split("=")[0]);
        shuzhi.set(3, Double.valueOf(mes1[2].split("=")[1]));
        xin = Integer.parseInt(mes1[3].split("\\|")[0].split("=")[1]);
        setYou(true);
        this.clBean = clBean;

    }

    public void TH(QualityClBean clBean) {
        Goodstable good = GoodsListFromServerUntil.getRgid(clBean.getRgid());
        assert good != null;
        String[] value = good.getValue().split("\\|");
        List<String> value1 = new ArrayList<>();
        for (String s : value) {
            if (!s.startsWith("点翠属性") && !s.startsWith("炼化属性&特技")) {
                value1.add(s);
            }
        }
        value1.removeIf(bb -> bb.equals(""));
        StringBuilder mes = null;
        for (String vv : value1) {
            if (vv.startsWith("培养")) {

                assert mes != null;
                mes.append("|");
                mes.append(clBean.getNewAttr());
                mes.append("|");
            }
            if (mes == null) {
                mes = new StringBuilder(vv);
            } else {
                mes.append("|").append(vv);
            }
        }
        assert mes != null;
        good.setValue(mes.toString());
        shuxing.set(0, shuxing.get(2));
        shuxing.set(1, shuxing.get(3));
        shuzhi.set(0, shuzhi.get(2));
        shuzhi.set(1, shuzhi.get(3));
        zong = xin;
        this.clBean = null;
        setYou(false);
        setZuo(true);

    }

    public RefineOperBtn getOperBtn2() {
        return operBtn2;
    }

    public void setOperBtn2(RefineOperBtn operBtn2) {
        this.operBtn2 = operBtn2;
    }

    public RefineOperBtn getOperBtn1() {
        return operBtn1;
    }

    public void setOperBtn1(RefineOperBtn operBtn1) {
        this.operBtn1 = operBtn1;
    }

    public RefineOperBtn getOperBtn3() {
        return operBtn3;
    }

    public void setOperBtn3(RefineOperBtn operBtn3) {
        this.operBtn3 = operBtn3;
    }

    public FormsOnOffBtn getOffBtn() {
        return offBtn;
    }

    public void setOffBtn(FormsOnOffBtn offBtn) {
        this.offBtn = offBtn;
    }

    public boolean isP() {
        return p;
    }

    public void setP(boolean p) {
        this.p = p;
    }

    public boolean isZuo() {
        return zuo;
    }

    public void setZuo(boolean zuo) {
        this.zuo = zuo;
    }

    public boolean isYou() {
        return you;
    }

    public void setYou(boolean you) {
        this.you = you;
    }

    public String[] getMes1() {
        return mes1;
    }

    public void setMes1(String[] mes1) {
        this.mes1 = mes1;
    }

    public static ImageIcon getIcon() {
        return icon;
    }

    public static void setIcon(ImageIcon icon) {
        DianQJpanel.icon = icon;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

    public ImageIcon getIcon2() {
        return icon2;
    }

    public void setIcon2(ImageIcon icon2) {
        this.icon2 = icon2;
    }

    public static Random getRand() {
        return rand;
    }

    public static void setRand(Random rand) {
        DianQJpanel.rand = rand;
    }
}
